﻿using System.ComponentModel;
using Cinch;

namespace TeamTasker.Client.Presentation.ViewModels
{
    public class HierarchicalTaskListViewModel : ViewModelBase
    {
        private ViewModelBase _TaskTreeViewModel;
        private ViewModelBase _AddEditTaskViewModel;

        public HierarchicalTaskListViewModel()
        {
            Mediator.Register(this);
            _TaskTreeViewModel = new TaskTreeViewModel() { ParentViewModel = this };
            _AddEditTaskViewModel = new AddEditTaskViewModel() { ParentViewModel = this };
            _CurrentViewModel = _TaskTreeViewModel;
        }

        private static PropertyChangedEventArgs _CurrentViewModelChangedEventArgs =
            ObservableHelper.CreateArgs<HierarchicalTaskListViewModel>(x => x.CurrentViewModel);

        private ViewModelBase _CurrentViewModel;
        public ViewModelBase CurrentViewModel
        {
            get { return _CurrentViewModel; }
            set {
                if (_CurrentViewModel != value)
                {
                    _CurrentViewModel = value;
                    NotifyPropertyChanged(_CurrentViewModelChangedEventArgs);
                }
            }
        }

        [MediatorMessageSink("GoAddEditTaskView")]
        private void GoAddEditTaskView(HierarchicalTaskListViewModel currentInstance)
        {
            CurrentViewModel = _AddEditTaskViewModel;
        }

        [MediatorMessageSink("GoToTaskTreeView")]
        private void GoToTaskTreeView(HierarchicalTaskListViewModel currentInstance)
        {
            CurrentViewModel = _TaskTreeViewModel;
        }
    }
}